package com.huiquan.vocab.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.vocab.domain.VocabElementReasonClassEntity;
import com.huiquan.vocab.domain.VocabElementReasonClassVO;
import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * 原因词分类 Dao
 *
 * @author leo
 * @time 2017年7月19日 下午4:32:52
 */
@Repository
public class VocabElementReasonClassDao extends EnhancedBaseDao<VocabElementReasonClassVO> {
	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "VOCAB_ELEMENT_REASON_CLASS.";

	public VocabElementReasonClassDao() {
		super(space);
	}

	/**
	 * 查询得到数量
	 * 
	 * @param params
	 * @return
	 */
	public int selectListSize(Map<String, Object> param) {
		return (int) this.object(space + "SELECT_LIST_SIZE", param, sqlMapClient);
	}

	/**
	 * 查询得到列表
	 * 
	 * @param params
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<VocabElementReasonClassVO> selectList(Map<String, Object> param) {
		return (List<VocabElementReasonClassVO>) this.list(space + "SELECT_LIST", param, sqlMapClient);
	}

	/**
	 * 初始化原因词分类临时表
	 */
	public void initReasonClassTempTable(List<Map<String, Object>> list) {
		this.insert(space + "INIT_REASON_CLASS_TEMP_TABLE", list, sqlMapClient);
	}

	/**
	 * 查找得到临时表中的原因词在element表中不存在的数量
	 * 
	 * @return
	 */
	public int selectCheckCount() {
		return (int) this.object(space + "SELECT_CHECK_COUNT", sqlMapClient);
	}

	/**
	 * 查找得到临时表中的原因词在element表中不存在的数据列表
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<String> selectCheckList() {
		return (List<String>) this.list(space + "SELECT_CHECK_LIST", sqlMapClient);
	}

	/**
	 * 将临时表数据导入到分类表
	 */
	public void importTempData(long userId, String userName) {
		Map<String, Object> param = new HashMap<>();
		param.put("userId", userId);
		param.put("userName", userName);
		this.insert(space + "IMPORT_TEMP_DATA", param, sqlMapClient);
	}

	/**
	 * 检索得到element关联同义词表后标注词无分类分级但是同义词有且仅有相同的一条分类分级的数据
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> selectDataBeforeExport() {
		return (List<Map<String, Object>>) this.list(space + "SELECT_DATA_WITH_SYNONYMY", sqlMapClient);
	}

	/**
	 * 为当前的标准词赋分类分级
	 * 
	 * @param list
	 */
	public void insertReasonClassBeforeExport(List<VocabElementReasonClassEntity> list) {
		this.insert(space + "INSERT_REASON_CLASS_BEFORE_EXPORT", list, sqlMapClient);
	}

	public void insertByStd() {
		this.insert(space + "INSERT_REASON_CLASS_BY_STD", sqlMapClient);
	}

}
